<template>
	<view>
		<view class="goods_item" v-for="(item,index) in goodsList" :key="index" @click="goDetail(item)">
			<image class="good_img" :src="item.goods_small_logo || defaultImg" mode=""></image>
			<view class="item_right">
				<text class="goods_name">{{item.goods_name}}</text>
				<text class="goods_price">{{item.goods_price | showPrice}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList: [],
				queryObj:{query:'',cid:'',pagenum:1,pagesize:10},
				total: 0,
				defaultImg: 'https://admin.cccecshop.com/admin/img/noneImg.23ad2cad.png'
			};
		},
		filters:{
			showPrice(val) {
				return '￥' + Number(val).toFixed(2)
			}
		},
		onLoad(option) {
			this.queryObj.cid = option.cid || ''
			this.queryObj.query = option.query || ''
			this.getGoodsList()
		},
		methods:{
			async getGoodsList(cb) {
				const {data} = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
				cb && cb()
				if (data.meta.status !== 200) return uni.$showMsg()
				this.goodsList = [...this.goodsList, ...data.message.goods]
				this.total = data.message.total
			},
			goDetail(val) {
				console.log(123)
				uni.navigateTo({
					url:'../goodsDetail/goodsDetail?goods_id=' + val.goods_id
				})
			}
		},
		onReachBottom() {
			if (this.queryObj.pagenum * this.queryObj.pagesize >= this.total) return uni.$showMsg(`仅有${this.total}条数据`)
			
			this.queryObj.pagenum++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.goodsList = []
			this.total = 0
			this.queryObj.pagenum = 1
			this.getGoodsList(() => uni.stopPullDownRefresh())
		}
	}
</script>

<style lang="scss">
.goods_item {
	display: flex;
	padding: 20rpx 10rpx;
	.good_img {
		display: inline-block;
		width: 200rpx;
		height: 200rpx;
		margin-right: 10rpx;
		border-radius: 4px;
	}
	.item_right {
		display: flex;
		flex: 1;
		flex-direction: column;
		justify-content: space-between;
		word-break: break-all;
		.goods_name {
			font-size: 12px;
		}
		.goods_price {
			color: #c00;
		}
	}
}
</style>
